//求2020年的所有星期天

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

public class Sunday {

    public static void main(String[] args) {

        List<String> weekenDays = getWeekends(2020);

        int count = 1;
        for(String weekDay: weekenDays){
            System.out.print(weekDay + " ");
            if(count++ == 7){
                System.out.println();
                count = 1;
            }
        }
    }

    public static List<String> getWeekends(int year){
        List<String> list = new ArrayList<String>();
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance(Locale.CHINA);
        cal.set(year, 0, 1);

        for(int day = 1; day <= cal.getActualMaximum(Calendar.DAY_OF_YEAR); day++){
            cal.set(Calendar.DAY_OF_YEAR, day);

            int weekDay = cal.get(Calendar.DAY_OF_WEEK);
            if(weekDay == Calendar.SUNDAY){
                list.add(sdf.format(cal.getTime()));
            }
        }
        return list;
    }
}
